package trainer;

import monster.Monster;
import monster.MonsterException;

public class Trade {

    private Trainer trainer1;
    private Trainer trainer2;
    private Monster monster1;
    private Monster monster2;

    public Trade(Trainer trainer1, Trainer trainer2, Monster monster1, Monster monster2) throws MonsterException {
        this.trainer1 = trainer1;
        this.trainer2 = trainer2;
        this.monster1 = monster1;
        this.monster2 = monster2;
        if (trainer1.hasMonster(monster1)) {
            throw new MonsterException(" trainer1 not have monster1 ");
        }
        if (trainer2.hasMonster(monster2)) {
            throw new MonsterException(" trainer2 not have monster2 ");
        }

    }

    public void doTrade() throws MonsterException {
        if ( trainer1.hasMonster(monster1) && trainer2.hasMonster(monster2) ){
            trainer1.removeMonster(monster1);
            trainer1.addMonster(monster2);
            trainer2.removeMonster(monster2);
            trainer2.addMonster(monster1);
        } else {
            throw new MonsterException(" trainer not have monster ");
        }

    }

}
